package com.kaka.bus.engine.home.info.bank;

import com.kaka.bus.bean.BankManagerBean;
import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.di.DataManager;
import com.kaka.bus.manager.Result;
import com.kaka.bus.manager.T;
import com.kaka.bus.mvp.RxPresenter;
import com.kaka.bus.util.U;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhangqi on 2017/4/27.
 */

public class BankCardManagerPresenter extends RxPresenter<BankCardManagerContract.View> implements BankCardManagerContract.Presenter {

    @Inject
    public BankCardManagerPresenter(DataManager dataManager) {
        super(dataManager);
    }

    @Override
    public void getBankCardManagerList(String userId) {
        mView.showDialog("查询银行卡..");

        mDataManager
                .getApi()
                .getBankCardList(userId,U.Sign(userId))
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<List<BankManagerBean>>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<List<BankManagerBean>> wrapper) {
                        mView.getBankCardManagerListSuccrss(wrapper);
                    }

                    @Override
                    protected void onFinish() {
                        super.onFinish();
                        mView.dissDialog();
                    }
                });
    }

    @Override
    public void changeBankStatus(String userId, String bankNum) {
        mView.showDialog("设置主卡中..");
        addSubscribe(mDataManager
                .getApi()
                .changeBankStatus(userId,bankNum,U.Sign(userId,bankNum))
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<String>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<String> stringHttpWrapper) {
                        mView.changeBankStatusSuccess(stringHttpWrapper);
                    }

                    @Override
                    protected void onFinish() {
                        mView.dissDialog();
                    }
                }));
    }

    @Override
    public void canBinding(String userId) {
        mView.showDialog("查询是否可以绑定银行卡...");
        addSubscribe(mDataManager
                .getApi()
                .canBinding(userId,U.Sign(userId))
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<String>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<String> o) {
                        mView.can(o);
                    }

                    @Override
                    protected void onFinish() {
                        mView.dissDialog();
                    }
                }));
    }
}
